package com.sinosoft.oms.mapper;

import com.sinosoft.oms.entity.oms.Order;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * @author:Frankiegg
 * @date:2018/5/15
 * @project:bee
 * @Modified By:
 **/
@Mapper
@Repository
public interface OrderMapper {

    /**
     * 插入订单
     * @param newOrder
     * @return boolean
     * @throws
     */
    @Insert("INSERT INTO oms_order (order_id, apply_no, policy_no, order_type, channel_source, \n" +
            "\tchannel_order_id, manage_com, agent_com, sale_channel, sale_type, agent_code, \n" +
            "\tagent_group, initial_pay_mode, rnewal_pay_mode, apply_date, uw_date, uw_status, \n" +
            "\tsign_date, sign_com, prem, amnt, effect_date, end_date, receipt_date, cus_receipt_date, \n" +
            "\tprint_type, check_status, import_lis_status, pay_status, sku_code, order_status, \n" +
            "\tis_specify_effect, is_record_check, is_portray_check, is_print_policy, is_need_invoice, \n" +
            "\tis_call_revisit, is_send_issuepol_notice, is_send_spec_notice, is_send_pe_notice, \n" +
            "\tis_send_ss_notice, is_send_fs_notice, is_send_ad_notice, create_user, gmt_create, \n" +
            "\tmodified_user, gmt_modified, is_deleted)\n" +
            "\tVALUES\n" +
            "\t(#{orderId}, #{applyNo}, #{policyNo}, #{orderType}, #{channelSource}, #{channelOrderId}, \n" +
            "\t#{manageCom}, #{agentCom}, #{saleChannel}, #{saleType}, #{agentCode}, #{agentGroup}, \n" +
            "\t#{initialPayMode}, #{rnewalPayMode}, #{applyDate}, #{uwDate}, #{uwStatus}, #{signDate}, \n" +
            "\t#{signCom}, #{prem}, #{amnt}, #{effectDate}, #{endDate}, #{receiptDate}, #{cusReceiptDate}, \n" +
            "\t#{printType}, #{checkStatus}, #{importLisStatus}, #{payStatus}, #{skuCode}, #{orderStatus}, \n" +
            "\t#{isSpecifyEffect}, #{isRecordCheck}, #{isPortrayCheck}, #{isPrintPolicy}, #{isNeedInvoice}, \n" +
            "\t#{isCallRevisit}, #{isSendIssuepolNotice}, #{isSendSpecNotice}, #{isSendPeNotice}, \n" +
            "\t#{isSendSsNotice}, #{isSendFsNotice}, #{isSendAdNotice}, #{createUser}, #{gmtCreate}, \n" +
            "\t#{modifiedUser}, #{gmtModified}, #{isDeleted})\n")
    boolean insertOrder(Order newOrder);

    /**
     * 根据ID删除订单
     * @param orderId
     * @return
     */
    @Delete("DELETE FROM oms_order,oms_order_product,oms_order_product_duty,oms_order_product_duty_prem," +
            "oms_order_product_duty_get,oms_order_appntoms_order_insured WHERE order_id = #{orderId}")
    boolean deleteOrderById(String orderId);

    /**
     * 根据ID修改订单
     * @param updateOrder
     * @return boolean
     * @throws
     */
    @Update("UPDATE oms_order \n" +
            "\tSET\n" +
            "\torder_id = #{orderId} , apply_no = #{applyNo} , policy_no = #{policyNo} , \n" +
            "\torder_type = #{orderType} , channel_source = #{channelSource} , \n" +
            "\tchannel_order_id = #{channelOrderId} , manage_com = #{manageCom} , \n" +
            "\tagent_com = #{agentCom} , sale_channel = #{saleChannel} , \n" +
            "\tsale_type = #{saleType} , agent_code = #{agentCode} , \n" +
            "\tagent_group = #{agentGroup} , initial_pay_mode = #{initialPayMode} , \n" +
            "\trnewal_pay_mode = #{rnewalPayMode} , apply_date = #{applyDate} , \n" +
            "\tuw_date = #{uwDate} , uw_status = #{uwStatus} , sign_date = #{signDate} , \n" +
            "\tsign_com = #{signCom} , prem = #{prem} , amnt = #{amnt} , effect_date = #{effectDate} , \n" +
            "\tend_date = #{endDate} , receipt_date = #{receiptDate} , cus_receipt_date = #{cusReceiptDate} , \n" +
            "\tprint_type = #{printType} , check_status = #{checkStatus} , import_lis_status = #{importLisStatus} , \n" +
            "\tpay_status = #{payStatus} , sku_code = #{skuCode} , order_status = #{orderStatus} , \n" +
            "\tis_specify_effect = #{isSpecifyEffect} , is_record_check = #{isRecordCheck} , \n" +
            "\tis_portray_check = #{isPortrayCheck} , is_print_policy = #{isPrintPolicy} , \n" +
            "\tis_need_invoice = #{isNeedInvoice} , is_call_revisit = #{isCallRevisit} , \n" +
            "\tis_send_issuepol_notice = #{isSendIssuepolNotice} , is_send_spec_notice = #{isSendSpecNotice} , \n" +
            "\tis_send_pe_notice = #{isSendPeNotice} , is_send_ss_notice = #{isSendSsNotice} , \n" +
            "\tis_send_fs_notice = #{isSendFsNotice} , is_send_ad_notice = #{isSendAdNotice} , \n" +
            "\tcreate_user = #{createUser} , gmt_create = #{gmtCreate} , modified_user = #{modifiedUser} , \n" +
            "\tgmt_modified = #{gmtModified} , is_deleted = #{isDeleted}\n" +
            "\t\n" +
            "\tWHERE\n" +
            "\torder_id = #{orderId} ")
    boolean updateOrderById(Order updateOrder);

    /**
     * 根据订单号查找订单信息
     * @param orderId
     * @return boolean
     * @throws
     */
    @Results(id = "order", value = {
            @Result(property = "orderId", column = "order_id"), @Result(property = "applyNo", column = "apply_no"), @Result(property = "policyNo", column = "policy_no"), @Result(property = "orderType", column = "order_type"),
            @Result(property = "channelSource", column = "channel_source"), @Result(property = "channelOrderId", column = "channel_order_id"), @Result(property = "manageCom", column = "manage_com"), @Result(property = "agentCom", column = "agent_com"),
            @Result(property = "saleChannel", column = "sale_channel"), @Result(property = "saleType", column = "sale_type"), @Result(property = "agentCode", column = "agent_code"), @Result(property = "agentGroup", column = "agent_group"),
            @Result(property = "initialPayMode", column = "initial_pay_mode"), @Result(property = "rnewalPayMode", column = "rnewal_pay_mode"), @Result(property = "applyDate", column = "apply_date"), @Result(property = "uwDate", column = "uw_date"),
            @Result(property = "uwStatus", column = "uw_status"), @Result(property = "signDate", column = "sign_date"), @Result(property = "signCom", column = "sign_com"), @Result(property = "prem", column = "prem"),
            @Result(property = "amnt", column = "amnt"), @Result(property = "effectDate", column = "effect_date"), @Result(property = "endDate", column = "end_date"), @Result(property = "receiptDate", column = "receipt_date"),
            @Result(property = "cusReceiptDate", column = "cus_receipt_date"), @Result(property = "printType", column = "print_type"), @Result(property = "checkStatus", column = "check_status"), @Result(property = "importLisStatus", column = "import_lis_status"),
            @Result(property = "payStatus", column = "pay_status"), @Result(property = "skuCode", column = "sku_code"), @Result(property = "orderStatus", column = "order_status"), @Result(property = "isSpecifyEffect", column = "is_specify_effect"),
            @Result(property = "isRecordCheck", column = "is_record_check"), @Result(property = "isPortrayCheck", column = "is_portray_check"), @Result(property = "isPrintPolicy", column = "is_print_policy"), @Result(property = "isNeedInvoice", column = "is_need_invoice"),
            @Result(property = "isCallRevisit", column = "is_call_revisit"), @Result(property = "isSendIssuepolNotice", column = "is_send_issuepol_notice"), @Result(property = "isSendSpecNotice", column = "is_send_spec_notice"), @Result(property = "isSendPeNotice", column = "is_send_pe_notice"),
            @Result(property = "isSendSsNotice", column = "is_send_ss_notice"), @Result(property = "isSendFsNotice", column = "is_send_fs_notice"), @Result(property = "isSendAdNotice", column = "is_send_ad_notice"), @Result(property = "createUser", column = "create_user"),
            @Result(property = "gmtCreate", column = "gmt_create"), @Result(property = "modifiedUser", column = "modified_user"), @Result(property = "gmtModified", column = "gmt_modified"), @Result(property = "isDeleted", column = "is_deleted")
    })
    @Select("SELECT \torder_id, apply_no, policy_no, order_type, channel_source, \n" +
            "\tchannel_order_id, manage_com, agent_com, sale_channel, sale_type, \n" +
            "\tagent_code, agent_group, initial_pay_mode, rnewal_pay_mode, apply_date, \n" +
            "\tuw_date, uw_status, sign_date, sign_com, prem, amnt, effect_date, \n" +
            "\tend_date, receipt_date, cus_receipt_date, print_type, check_status, \n" +
            "\timport_lis_status, pay_status, sku_code, order_status, is_specify_effect, \n" +
            "\tis_record_check, is_portray_check, is_print_policy, is_need_invoice, \n" +
            "\tis_call_revisit, is_send_issuepol_notice, is_send_spec_notice, \n" +
            "\tis_send_pe_notice, is_send_ss_notice, is_send_fs_notice, is_send_ad_notice, \n" +
            "\tcreate_user, gmt_create, modified_user, gmt_modified, is_deleted\n" +
            "\tFROM \n" +
            "\toms_order \n" +
            "\tWHERE  \n" +
            "\torder_id = #{orderId} ")
    Order findOrderById(String orderId);
}
